package com.example.combwyaq.visualinterface.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.example.combwyaq.R;
import com.example.combwyaq.db.DaoManager;
import com.example.combwyaq.entity.UserEntity;
import com.flyco.tablayout.CommonTabLayout;

import java.util.List;

public class HomePageActivity extends AppCompatActivity  {
    private ImageView back;
    private Button goPersonal;
    private ImageView touPage;
    private TextView pageName;
    private TextView pageLeval;
    private TextView comedate;
    private CommonTabLayout comPage;
    private ViewPager vpPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page);
        initView();


    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        goPersonal = (Button) findViewById(R.id.go_Personal);
        touPage = (ImageView) findViewById(R.id.tou_page);
        pageName = (TextView) findViewById(R.id.page_name);
        pageLeval = (TextView) findViewById(R.id.page_leval);
        comedate = (TextView) findViewById(R.id.comedate);
        comPage = (CommonTabLayout) findViewById(R.id.com_page);
        vpPage = (ViewPager) findViewById(R.id.vp_page);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        goPersonal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HomePageActivity.this, PersonalDetailsActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        try {
            List<UserEntity> userEntities = DaoManager.getInstance().getDaoSession().loadAll(UserEntity.class);
            LogUtils.json(userEntities);
            if (userEntities.get(0).getUser_img()==null){
                Glide.with(this).load(R.drawable.pn_placeholder).into(touPage);
            }else{
                Glide.with(this).load(userEntities.get(0).getUser_img()).into(touPage);
                pageName.setText(userEntities.get(0).getUser_name());
                pageLeval.setText("LV."+userEntities.get(0).getUser_integral());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
